//
//  MyFootViewController.m
//  Cheirapsis
//
//  Created by wangning on 15/11/16.
//  Copyright © 2015年 mohe. All rights reserved.
//

#import "MyFootViewController.h"
#import "StoreViewController.h"
#import "Define.h"
#import "Request.h"
#import "UIImageView+WebCache.h"
#import "MBProgressHUD.h"

@interface MyFootViewController ()

@end

@implementation MyFootViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self getData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)getData{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [[Request sharedInstance] getMyFeet:nil content:^(NSArray *arr) {
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        _dataSource = arr;
        [_tableView reloadData];
    }];
}

#pragma -mark setCell
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *identifier = [NSString stringWithFormat:@"identifier%ld",(long)indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    
    
    NSDictionary *dic = [_dataSource objectAtIndex:indexPath.row];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(15*F_WIDTH, 10*F_HEIGHT, 80*F_WIDTH, 80*F_HEIGHT)];
    [imageView sd_setImageWithURL:[NSURL URLWithString:dic[@"storeImageArr"][0]]];
    imageView.layer.masksToBounds = YES;
    imageView.layer.cornerRadius = 10*F_WIDTH;
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(100*F_WIDTH, 10*F_HEIGHT, 200*F_WIDTH, 15*F_HEIGHT)];
    titleLabel.text = dic[@"storeName"];
    
    UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(100*F_WIDTH, 25*F_HEIGHT, 200*F_WIDTH, 40*F_HEIGHT)];
    contentLabel.text = dic[@"storeDescripition"];
    contentLabel.font = [UIFont systemFontOfSize:12*F_WIDTH];
    contentLabel.numberOfLines = 0;
    
    UILabel *AddNumber = [[UILabel alloc] initWithFrame:CGRectMake(100*F_WIDTH, 80*F_HEIGHT, 100*F_WIDTH, 15*F_HEIGHT)];
    AddNumber.text = dic[@"storeAddress"];
    AddNumber.font = [UIFont systemFontOfSize:12*F_WIDTH];
    
    UILabel *enterLable = [[UILabel alloc] initWithFrame:CGRectMake(250*F_WIDTH, 80*F_HEIGHT, 50*F_WIDTH, 15*F_HEIGHT)];
    enterLable.text = @"点击进入";
    enterLable.backgroundColor = [UIColor colorWithRed:159/255.0 green:203/255.0 blue:239/255.0 alpha:1.0];
    enterLable.font = [UIFont systemFontOfSize:10*F_WIDTH];
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(15*F_WIDTH, 99*F_HEIGHT, 305*F_WIDTH, 0.6)];
    lineView.backgroundColor = [UIColor lightGrayColor];
    
    [cell.contentView addSubview:imageView];
    [cell.contentView addSubview:titleLabel];
    [cell.contentView addSubview:contentLabel];
    [cell.contentView addSubview:AddNumber];
    [cell.contentView addSubview:enterLable];
    [cell.contentView addSubview:lineView];
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100*F_HEIGHT;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dic = [_dataSource objectAtIndex:indexPath.row];
    StoreViewController *store = [[StoreViewController alloc] init];
    store.dic = dic;
    [self.navigationController pushViewController:store animated:YES];
}

@end
